#!/usr/bin/python
# -*- coding: UTF-8 -*-
import jieba
import pandas as pd

def spliteText():
    s = open('hlm.txt', 'r',encoding='utf-8',errors="ignore")
    q = s.read()
    f = q.split('\n')
    x = 1
    for i in f:
        b = open('data/' + str(x) + '.txt', 'w',encoding="utf-8")
        b.write(i)
        x += 1
    s.close


def get_show_in():
    result={"宝玉":[],"黛玉":[],"宝钗":[]}
    x=1
    while  x<=2065:
        f = open('data/' + str(x) + '.txt', 'r',encoding="utf-8").read()
        words=list(jieba.cut(f))
        if "黛玉" in words:
            result["黛玉"].append(1)
        else:
            result["黛玉"].append(0)
        if "宝玉" in words:
            result["宝玉"].append(1)
        else:
            result["宝玉"].append(0)
        if "宝钗" in words:
            result["宝钗"].append(1)
        else:
            result["宝钗"].append(0)
        x+=1
    data=pd.DataFrame(result)
    return data


def cumAllshow(data):
    result = {"role":[],"宝玉": [], "黛玉": [], "宝钗":[]}
    for a in data.columns.values:
        x = baoyu = daiyu = baochai=0
        while x<=2064:
            if data.iloc[x][a]==1:
                if data.iloc[x]["宝玉"]==1:
                    baoyu+=1
                if data.iloc[x]["黛玉"]==1:
                    daiyu+=1
                if data.iloc[x]["宝钗"]==1:
                    baochai+=1

            x+=1
        result["role"].append(a)
        result["宝玉"].append(baoyu)
        result["黛玉"].append(daiyu)
        result["宝钗"].append(baochai)
    data=pd.DataFrame(result)
    data.to_csv("lmw.csv",encoding="utf-8")









def main():

    data=pd.read_csv("lmw.csv",encoding="utf-8",index_col="role")

    data=data.drop(["Unnamed: 0"],axis=1)
    data = data.reindex( columns=["宝钗","黛玉","宝玉"])
    data.to_csv("hlm.csv",encoding="utf-8")
    print(data)










if __name__ == '__main__':
    main()


